package com.itboye.boyeshoping.response;

import com.google.gson.reflect.TypeToken;
import com.itboye.boyeshoping.inf.IShoping;
import com.itboye.boyeshoping.util.volley.BaseErrorListener;
import com.itboye.boyeshoping.util.volley.BaseNetRepository;
import com.itboye.boyeshoping.util.volley.BaseSuccessReqListener;
import com.itboye.boyeshoping.util.volley.ByJsonRequest;
import com.itboye.boyeshoping.util.volley.ICompleteListener;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;


/**
 * Created by Administrator on 2018/7/27 0027.
 */

public class ShopResponse extends BaseNetRepository implements IShoping {
    public String api="100";
    public String api1="101";

    private String login = "By_UserTbAccount_registerTb";// 登录
    private String senMsg= "By_SecurityCode_send";//发送验证码
    private String checkMsg="By_SecurityCode_verify";//验证验证吗



    public ShopResponse(ICompleteListener iCompleteListener) {
        super(iCompleteListener);
    }

    @Override
    public void login(String nickname, String openSid, String openId, String avatarUrl, String topAccessToken) {

        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<>();
        map.put("nickname",nickname);
        map.put("openSid",openSid);
        map.put("openId",openId);
        map.put("avatarUrl",avatarUrl);
        map.put("topAccessToken",topAccessToken);
        map.put("username","aaa");
        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(login, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<String>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void sendMsg(String codeType, String mobile,String send_type,String expire_time,String country) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = api;
        Map<String, Object> map = new HashMap<>();
        map.put("codeType",codeType);
        map.put("mobile",mobile);

        map.put("country",country);
        map.put("expire_time",expire_time);
        map.put("send_type",send_type);

        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(senMsg, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<String>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void checkMsg(String codeType, String accepter, String country, String code) {
        Type type = new TypeToken<String>() {
        }.getType();
        String apiVer = api1;
        Map<String, Object> map = new HashMap<>();
        map.put("codeType",codeType);
        map.put("accepter",accepter);

        map.put("country",country);
        map.put("code",code);
        (new ByJsonRequest.Builder<String>())
                .setTypeVerParamsAndReturnClass(checkMsg, apiVer, map, type)
                .requestListener(
                        new BaseSuccessReqListener<String>(
                                getListener()))
                .errorListener(new BaseErrorListener(getListener()))
                .desEncodeThenBuildAndSend();
    }

    @Override
    public void bindPhone(String country, String code, String inviter, String mobile) {

    }
}
